package kyssion.leetcode.num201_250;

import kyssion.leetcode.util.ListNode;
import kyssion.leetcode.util.ShowUtil;

public class code206_反转链表 {

    public static void main(String[] args) {
        ListNode listNode = ListNode.createListNode(new int[]{
                1,2,3,4,5
        });
        listNode = new code206_反转链表().reverseList(listNode);
        ShowUtil.showNode(listNode);
    }

    public ListNode reverseList(ListNode head) {
        if(head == null){
            return head;
        }
        ListNode oldHead = head;
        ListNode next = head.next;
        while(next!=null){
            ListNode nextHead = next.next;
            next.next = head;
            head = next;
            next = nextHead;
        }
        oldHead.next = null;
        return head;
    }
}
